home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Utilities / DockMultiPrint / Source / UtilityObject.m < prev   
Text File  |  1992-07-27  |  3KB  |  115 lines

  1.  
  2. /* Generated by Interface Builder */
  3. #import <appkit/publicWraps.h>
  4. #import <appkit/Application.h>
  5. #import <appkit/Listener.h>
  6. #import <appkit/Speaker.h>
  7. #import <appkit/Window.h>
  8. #import <string.h>
  9. #import <appkit/nextstd.h>
  10. #import <cthreads.h>
  11. #import "UtilityObject.h"
  12.  
  13. @implementation UtilityObject
  14.  
  15. -appDidInit:sender
  16. {
  17.     unsigned int wn;
  18.     id speaker = [NXApp appSpeaker];
  19.     
  20.     NXConvertWinNumToGlobal([[NXApp appIcon] windowNum], &wn);
  21.     [speaker setSendPort:NXPortFromName(NX_WORKSPACEREQUEST, NULL)];
  22.     [speaker registerWindow:wn toPort:[[NXApp appListener] listenPort]];    
  23.     return self;
  24. }
  25.  
  26. - printFiles:anObject
  27. /* Send the selected files to the printer. We start from the end of the list.
  28.  * Probably should start from the beginning...
  29.  */
  30. {
  31.     char *fileName, *thePath, *ptr;
  32.     char command[1024];
  33.     BOOL loopEnd = FALSE;
  34.     
  35.     while (loopEnd == FALSE)
  36.        {
  37.        fileName = iconPathList;
  38.        if (ptr = rindex(iconPathList, '/'))
  39.           {
  40.       *ptr = '\0';
  41.       fileName = ptr + 1;
  42.       if (ptr = rindex(iconPathList, '\t'))
  43.          {
  44.          *ptr = '\0';
  45.          thePath = ptr + 1;
  46.          }
  47.       else
  48.          {
  49.          thePath = iconPathList;
  50.          loopEnd = TRUE;
  51.          }
  52.       chdir(thePath);
  53.       }
  54.        if ( (ptr = rindex(fileName, '.')) &&
  55.           (memcmp(ptr + 1, "h", 1) == 0 ||
  56.           memcmp(ptr + 1, "m", 1) == 0) )
  57.       {
  58.           sprintf(command, "vgrind %s", fileName);
  59.           system(command);
  60.       }
  61.        else
  62.           NXLogError("DockPrint encountered invalid file extension.");
  63.        }
  64.  
  65.     if (iconPathList)
  66.        {
  67.        NX_FREE(iconPathList);
  68.        iconPathList = NULL;
  69.        }
  70.     return anObject;
  71. }
  72.  
  73. static any_t printThread(id anObject)
  74. {   
  75.     [anObject printFiles:anObject];
  76.     return anObject;
  77. }   
  78.  
  79. - (int)iconEntered:(int)windowNum at:(double)x :(double)y
  80.     iconWindow:(int)iconWindowNum 
  81.     iconX:(double)iconX iconY:(double)iconY
  82.     iconWidth:(double)iconWidth 
  83.     iconHeight:(double)iconHeight
  84.     pathList:(char *)pathList
  85. /* Sometimes this method is not invoked when it should be. The app appears to
  86.  * be out of touch, clicking it will wake it up.
  87.  */
  88. {
  89.     if (iconPathList)
  90.        NX_FREE(iconPathList);
  91.     iconPathList = NXCopyStringBuffer(pathList);
  92.         
  93.     return 0;
  94. }
  95.  
  96. - (int)iconReleasedAt:(double)x :(double)y ok:(int *)flag
  97. {    
  98.     cthread_detach(cthread_fork((cthread_fn_t)printThread, (any_t)self));
  99.     [NXApp hide:self];
  100.     *flag = 1;
  101.     return 0;
  102. }
  103.  
  104. - (int)iconExitedAt:(double)x :(double)y
  105. {
  106.     if (iconPathList)
  107.        {
  108.        NX_FREE(iconPathList);
  109.        iconPathList = NULL;
  110.        }
  111.     return 0;  
  112. }
  113.  
  114. @end
  115.